Skip to content

Keep comments written before an empty comment line - #314

Open
jayhemnani9910 wants to merge 1 commit into
php-gettext:masterfrom
jayhemnani9910:fix/po-keep-comments-before-empty-comment
Open

jayhemnani9910 wants to merge 1 commit into
php-gettext:masterfrom
jayhemnani9910:fix/po-keep-comments-before-empty-comment

Conversation

@jayhemnani9910

Copy link
Copy Markdown

PoLoader loses every comment that comes before a bare # line. In a standard .po header (as written by msginit/xgettext, and by PoGenerator itself) that is the whole description:

# German translation for myapp.
# Copyright (C) 2024 Example Inc.
# This file is distributed under the same license as the myapp package.
# Jane Doe <jane@example.com>, 2024.
#
#, fuzzy
msgid ""
msgstr ""

getDescription() returns null, and loading then saving the file with PoGenerator drops the copyright, license and translator lines. A translator comment followed by a # line is lost the same way.

Since #296 a bare # is read as an empty line, which ends the current entry; an entry with only comments is empty and is discarded. Now a bare # only ends an entry once the entry has a msgid or translation (the msgcat case from #296). Before that it is skipped, and the comments carry on to the entry that follows.

Added testCommentsBeforeEmptyComment to PoLoaderTest (header description, fuzzy flag, and a translator comment between # lines); it fails without the change. StrictPoLoader keeps these comments already, so the test is only for PoLoader. phpunit 106 tests OK, phpcs and phpstan clean. Loading and generating the file above now keeps the four header lines; on master they are gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant